package drds.server.sqlparser.sqlobject.expression.name;

import drds.server.sqlparser.sqlobject.expression.AbstractExpression;
import drds.server.sqlparser.sqlobject.expression.Expression;
import drds.server.sqlparser.visitor.Visitor;

/**
 * 
 * @author 曹正辉<330937205@qq.com>
 * 
 */
public class TableAliasName$ColumnName extends AbstractExpression implements IName {

	/** 表别名 */
	private Expression tableAliasName;
	private String columnName;

	public TableAliasName$ColumnName(Expression tableAliasName, String columnName) {
		setTableAliasName(tableAliasName);
		this.columnName = columnName;
	}

	public void setTableAliasName(Expression tableAliasName) {
		if (tableAliasName != null) {
			tableAliasName.setParent(this);
		}
		this.tableAliasName = tableAliasName;
	}

	public Expression getTableAliasName() {
		return this.tableAliasName;
	}

	public void setColumnName(String columnName) {
		this.columnName = columnName;
	}

	public String getName() {
		return this.columnName;
	}

	public void output(StringBuffer sb) {
		this.tableAliasName.output(sb);
		sb.append(".");
		sb.append(this.columnName);
	}

	protected void accept0(Visitor visitor) {
		if (visitor.visit(this)) {
			acceptChild(visitor, this.tableAliasName);
		}

		visitor.endVisit(this);
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((columnName == null) ? 0 : columnName.hashCode());
		result = prime * result + ((tableAliasName == null) ? 0 : tableAliasName.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object o) {
		if (this == o) {
			return true;
		}
		if (o == null) {
			return false;
		}
		if (!(o instanceof TableAliasName$ColumnName)) {
			return false;
		}
		TableAliasName$ColumnName other = (TableAliasName$ColumnName) o;

		if (tableAliasName == null) {
			if (other.tableAliasName != null) {
				return false;
			}
		} else if (!tableAliasName.equals(other.tableAliasName)) {
			return false;
		}
		if (columnName == null) {
			if (other.columnName != null) {
				return false;
			}
		} else if (!columnName.equals(other.columnName)) {
			return false;
		}

		return true;
	}

}
